const Mock = require('mockjs')

const List = []
const count = 100

const baseContent = '<p>I am testing data, I am testing data.</p><p><img src="https://wpimg.wallstcn.com/4c69009c-0fd4-4153-b112-6cb53d1cf943"></p>'
const image_uri = 'https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3'

for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    id: '@increment',
    number:'@integer(8)',
    customername:'@first',
    phone: '@phone',
    onshoptime: '@integer(0,100)',
    contacttype: '@integer(1,3)',
    customersource: '@integer(1,4)',
    'intentioncar|1': ['宝马', '奥迪', '本田', '日立','特斯拉'],
    intentionprice: '@float(0, 100, 2, 2)',
    shopprice: '@float(0, 100, 2, 2)',
    guider: '@first',
    receptiontype: '@integer(1,5)',
    state: '@integer(0,1)',
    receptiontime:'@datetime',
    starttime:'@datetime',
    endtime:'@datetime',
    visitornumber:'@integer(1,5)',
    buytimes:'@integer(0,5)',
    customerweixin:'@weixin',
    customergender:'@integer(0,1)',

  }))
}

const AnalyzeList=[];
for(let i=0;i<12;i++){
  AnalyzeList.push(Mock.mock({
    id: '@increment',
    guider:'@first',
    target:'@integer(20,50)',
    current:'@integer(0,40)'
  }))
}

const IntentionList=[];
for(let i=0;i<count;i++){
  IntentionList.push(Mock.mock({
    id: '@increment',
    guider:'@first',
    number:'@integer(209011234,879011234)',
    customername:'@first',
    phone:'@phone',
    intentiondate:'@datetime',
    intentiondays:'@integer(3,40)',
    revisittimes:'@integer(0,10)',
    recentvisitdate:'@date',
    intentionlevel:'@integer(1,4)',
    isfail:'@integer(0,1)',
    overduetimes:'@integer(0,6)',
    'intentioncar|1': ['宝马', '奥迪', '本田', '日立','特斯拉'],
    intentionprice: '@float(0, 100, 2, 2)',
    shopprice: '@float(0, 100, 2, 2)',
    state:'@integer(0,1)',
    nextvisitdate:'@date',
  }))

}

const GuiderList=[];
for(let i=0;i<20;i++){
  GuiderList.push(Mock.mock({
    id:'@increment',
    name:'@first'
  }))
}

  
  module.exports = [
    // recordlist
    {
      url: '/api/reception/recordlist',
      type: 'get',
      response: config => {
        const { importance, type, title, page = 1, limit = 20, sort } = config.query
  
        let mockList = List.filter(item => {
          if (importance && item.importance !== +importance) return false
          if (type && item.type !== type) return false
          if (title && item.title.indexOf(title) < 0) return false
          return true
        })
  
        if (sort === '-id') {
          mockList = mockList.reverse()
        }
  
        const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
  
        return {
          code: '10000',
          data: {
            total: mockList.length,
            items: pageList
          }
        }
      }
    },

    //单个数据

    {
      url: '/api/reception/recorddetails',
      type: 'get',
      response: config => {
          var rd=parseInt(Math.random()*100)
          var item=List[rd];
          return {
            code: '10000',
            data: item
        }
      }
    },

    //接待统计分析
    {
      url: '/api/reception/analyze',
      type: 'get',
      response: config => {
          var mockList=AnalyzeList.filter(o=>true);
          return {
            code: '10000',
            data: {
              total: mockList.length,
              items: mockList
            }
        }
      }
    },
// intentionlist
{
  url: '/api/reception/intentionlist',
  type: 'get',
  response: config => {
    const { importance, type, title, page = 1, limit = 20, sort } = config.query

    let mockList = IntentionList.filter(item => {
      if (importance && item.importance !== +importance) return false
      if (type && item.type !== type) return false
      if (title && item.title.indexOf(title) < 0) return false
      return true
    })

    if (sort === '-id') {
      mockList = mockList.reverse()
    }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

    return {
      code: '10000',
      data: {
        total: mockList.length,
        items: pageList
      }
    }
  }
},

  //getguiderlist
  {
    url: '/api/reception/guiderlist',
    type: 'get',
    response: config => {
        const { key } = config.query
        var mockList=[];
        if(key){
          mockList=GuiderList.filter(o=>o.name.indexOf(key)>-1);
        }else{
          mockList=GuiderList.filter(o=>true);
        }
        return {
          code: '10000',
          data: {
            total: mockList.length,
            items: mockList
          }
      }
    }
  },


  ]
  